package me.mononin.dilechat.activities;

import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.target.ImageViewTarget;

import net.qiujuer.genius.ui.compat.UiCompat;

import butterknife.BindView;
import me.mononin.common.common.app.Activity;
import me.mononin.dilechat.R;
import me.mononin.dilechat.fragments.account.AccountInfoFragment;

public class AccountActivity extends Activity {

    private AccountInfoFragment mFragment;

    @BindView(R.id.im_bg)
    ImageView mBg;

    @Override
    protected int getContentId() {
        return R.layout.activity_account;
    }

    /**
     * 启动当前Activity
     * @param context 传递上下文
     */
    public static void start(Context context){
        context.startActivity(new Intent(context,AccountActivity.class));
    }


    @Override
    protected void initWidget() {
        super.initWidget();
        mFragment = new AccountInfoFragment();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.lay_container,mFragment)
                .commit();


        Glide.with(this)
                .load(R.drawable.bg_src_tianjin)
                .centerCrop()
                .into(new ImageViewTarget<GlideDrawable>(mBg) {
                    @Override
                    protected void setResource(GlideDrawable resource) {
                        //通过Glide拿到drawable
                        Drawable drawable = resource.getCurrent();
                        //通过适配类包装drawable
                        drawable = DrawableCompat.wrap(drawable);
                        //对Drawable进行着色
                        drawable.setColorFilter
                                (UiCompat.getColor(getResources(),R.color.colorAccent),
                                        PorterDuff.Mode.SCREEN);
                        this.view.setImageDrawable(drawable);
                    }
                });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        mFragment.onActivityResult(requestCode,resultCode,data);

    }
}
